/*****************************************************************************
 *
 * Copyright (c), 2004-2020,ShangHai Neotune Information Technology Co., Ltd.
 *
 * Module Name : nvutils.h
 *
 * Author :    sean
 *
 * Date :    2004-02-05
 *
 * Version :    1.00
 *
 * Description :    
 *
 * Other :    
 *
 * Data Structure List: <Main Data Structure>
 *
 * Modification History
 * ---------------------------------------------------------------------------
 *  1: Data :      2004-02-05
 *    Author :     sean
 *    Version :    V100R001M00
 *    Modification : creation
 *
*****************************************************************************/

#include "asn1conf.h"
#include "asn1.h"
#include "buffer_snmp.h"
#include "snmpdefs.h"
#include <stdio.h>

#if !defined(nvutils_inc)
#define nvutils_inc

#define NV_VIEW_MAXNAMELEN 32

typedef struct TB_S 
        {
        int   token_tag;        /* Tag for this token */
        char *token_string;     /* String representation for this token */
        } TB_T;

typedef struct MODS_S
        {
        struct MODS_S   *next;  /* The next entry in the linked list */
        PTR_T            data;  /* The structure for the entity */
        PTR_T            newdata; /* new info for the entry */
        INT_32_T         flags; /* Flags to describe what to do with
                                   this entity.  Currently only
                                   destroy is defined */
#if (INSTALL_ENVOY_SNMP_RFC2275_VIEWS)
        bits8_t         name[NV_VIEW_MAXNAMELEN];  /* the name of the view */
        ALENGTH_T       namelen;                   /* length of the name */
#endif
        } MODS_T;

#define NV_MOD_DESTROY 1

#define TVERSION 1

#define TCOMMENT  1
#define TPREAMBLE 2
#define TVIEW     3
#define TMYAGENT  4
#define TAGENT    5
#define TACCESS   6
#define TCONTEXT  7
#define TUSER     8
#define TV3MYENGINE  9
#define TV3ENGINE   10
#define TV3USER     11
#define TV3GROUP    12
#define TV3ACCESS   13
#define TV3CONTEXT  14
#define TV3TADDR    15
#define TV3TPARM    16
#define TV3NTFY     17
#define TV3NPROF    18
#define TV3NFILT    19
#define TV3TRAP     20

#define TVID             1
#define TVSTATUS         2
#define TVSTORAGE        3
#define TVMASK           4
#define TVTYPE           5

#define TAGID            1
#define TAGBOOTS         2

#define TACID            1
#define TACUNAME         2
#define TACCNAME         3
#define TACQOS           4
#define TACPRIV          5
#define TACRIND          6
#define TACWIND          7

#define TCID             1
#define TCCNAME          2
#define TCFLAGS          3

#define TUID             1
#define TUUNAME          2
#define TUAUTHPROT       3
#define TUAUTHKEY        4

#define TENGID           1
#define TENGBOOTS        2
#define TENGTADDR        3

#define TV3UID          1
#define TV3UUNAME       2
#define TV3UAUTHPROT    3
#define TV3UAUTHKEY     4
#define TV3UPRIVPROT    5
#define TV3UPRIVKEY     6
#define TV3USTATUS      7
#define TV3USTORAGE     8

#define TV3GUSER        1
#define TV3GMODEL       2
#define TV3GGROUP       3
#define TV3GSTATUS      4
#define TV3GSTORAGE     5

#define TV3ACGROUP       1
#define TV3ACPREFIX      2
#define TV3ACMATCH       3
#define TV3ACMODEL       4
#define TV3ACLEVEL       5
#define TV3ACREAD        6
#define TV3ACWRITE       7
#define TV3ACNOTIFY      8
#define TV3ACSTATUS      9
#define TV3ACSTORAGE    10

#define TV3CNAME         1

#define TV3TADDRNAME     1
#define TV3TADDRTDOM     2
#define TV3TADDRTADDR    3
#define TV3TADDRTMASK    4
#define TV3TADDRTMOUT    5
#define TV3TADDRRETRY    6
#define TV3TADDRTLIST    7
#define TV3TADDRTMMS     8
#define TV3TADDRPARMS    9
#define TV3TADDRSTORAGE 10
#define TV3TADDRSTATUS  11

#define TV3TPARMNAME     1
#define TV3TPARMMPMOD    2
#define TV3TPARMSECMOD   3
#define TV3TPARMSECNAM   4
#define TV3TPARMSECLVL   5
#define TV3TPARMSTORAGE  6
#define TV3TPARMSTATUS   7

#define TV3NTFYNAME      1
#define TV3NTFYTAG       2
#define TV3NTFYTYPE      3
#define TV3NTFYSTORAGE   4
#define TV3NTFYSTATUS    5

#define TV3NPROFPARM     1
#define TV3NPROFNAME     2
#define TV3NPROFSTORAGE  3
#define TV3NPROFSTATUS   4

#define TV3NFILTPNAME    1
#define TV3NFILTSTREE    2
#define TV3NFILTMASK     3
#define TV3NFILTTYPE     4
#define TV3NFILTSTORAGE  5
#define TV3NFILTSTATUS   6

#define TV3TRAPNAME      1
#define TV3TRAPOID       2
#define TV3TRAPTYPE      3
#define TV3TRAPVALUE     4
#define TV3TRAPCOUNT     5

extern int  SNMP_NV_Config              (char *);
extern void SNMP_NV_Clean               (void);
extern int  SNMP_NV_Write               (int);
extern void SNMP_NV_Doit                (void);

struct SNMP_PKT_S;
struct VB_S;

#if (INSTALL_ENVOY_SNMP_V3_TARGET) && (INSTALL_ENVOY_SNMP_V3_NOTIFY)
typedef struct SNMPV3_TRAP_S
    {
    struct SNMPV3_TRAP_S *next;
    EBUFFER_T             trap_name;
    VBL_T                *vblp;
    } SNMPV3_TRAP_T;

extern SNMPV3_TRAP_T *trap_root;
#endif

#if (INSTALL_ENVOY_SNMP_RFC1445_VIEWS)
struct VIEWLEAF_S;
extern int  SNMP_NV_View_Add_Mod        (struct VIEWLEAF_S *, INT_32_T);
#endif

#if (INSTALL_ENVOY_SNMP_RFC2275_VIEWS)
struct VIEWLEAF_S;
extern sbits32_t  SNMP_NV_View_2275_Add_Mod   (struct VIEWLEAF_S *,
                                               struct VIEWLEAF_S *,
                                               sbits32_t);
extern sbits32_t SNMP_view_2275_test    (struct SNMP_PKT_S *, struct VB_S *,
                                         struct VIEWLEAF_S *,
                                         struct VIEWLEAF_S *);
extern void      SNMP_view_2275_set     (struct SNMP_PKT_S *, struct VB_S *,
                                         struct VIEWLEAF_S *,
                                         struct VIEWLEAF_S *);
extern void      SNMP_view_2275_backout (struct VIEWLEAF_S *,
                                         struct VIEWLEAF_S *);
extern int       SNMP_view_2275_undo    (struct SNMP_PKT_S *, struct VB_S *,
                                         struct VIEWLEAF_S *,
                                         struct VIEWLEAF_S *);
extern void      SNMP_view_2275_finished (void);

#endif

#if (INSTALL_ENVOY_SNMP_VERSION_3)
struct SNMP_GROUP_S;
extern sbits32_t  SNMP_NV_V3_Group_Add_Mod    (struct SNMP_GROUP_S *,
                                               struct SNMP_GROUP_S *,
                                               sbits32_t);
extern sbits32_t  SNMP_v3_group_test     (struct SNMP_PKT_S *, struct VB_S *,
                                          struct SNMP_GROUP_S *,
                                          struct SNMP_GROUP_S *);
extern void       SNMP_v3_group_set      (struct SNMP_PKT_S *, struct VB_S *,
                                          struct SNMP_GROUP_S *,
                                          struct SNMP_GROUP_S *);
extern void       SNMP_v3_group_backout  (struct SNMP_GROUP_S *,
                                          struct SNMP_GROUP_S *);
extern int        SNMP_v3_group_undo     (struct SNMP_PKT_S *, struct VB_S *,
                                          struct SNMP_GROUP_S *,
                                          struct SNMP_GROUP_S *);
extern void       SNMP_v3_group_finished (void);


struct SNMP_ACCESS_S;
extern sbits32_t  SNMP_NV_V3_Access_Add_Mod   (struct SNMP_ACCESS_S *,
                                               struct SNMP_ACCESS_S *,
                                               sbits32_t);
extern sbits32_t  SNMP_v3_access_test     (struct SNMP_PKT_S *, struct VB_S *,
                                           struct SNMP_ACCESS_S *,
                                           struct SNMP_ACCESS_S *);
extern void       SNMP_v3_access_set      (struct SNMP_PKT_S *, struct VB_S *,
                                           struct SNMP_ACCESS_S *,
                                           struct SNMP_ACCESS_S *);
extern void       SNMP_v3_access_backout  (struct SNMP_ACCESS_S *,
                                           struct SNMP_ACCESS_S *);
extern int        SNMP_v3_access_undo     (struct SNMP_PKT_S *, struct VB_S *,
                                           struct SNMP_ACCESS_S *,
                                           struct SNMP_ACCESS_S *);
extern void       SNMP_v3_access_finished (void);


struct SNMP_USER_S;
extern sbits32_t  SNMP_NV_V3_User_Add_Mod     (struct SNMP_USER_S *,
                                               struct SNMP_USER_S *,
                                               sbits32_t);
extern sbits32_t  SNMP_v3_user_test     (struct SNMP_PKT_S *, struct VB_S *,
                                         struct SNMP_USER_S *,
                                         struct SNMP_USER_S *);
extern void       SNMP_v3_user_set      (struct SNMP_PKT_S *, struct VB_S *,
                                         struct SNMP_USER_S *,
                                         struct SNMP_USER_S *);
extern void       SNMP_v3_user_backout  (struct SNMP_USER_S *,
                                         struct SNMP_USER_S *);
extern int        SNMP_v3_user_undo     (struct SNMP_PKT_S *, struct VB_S *,
                                         struct SNMP_USER_S *,
                                         struct SNMP_USER_S *);
extern void       SNMP_v3_user_finished (void);

#if (INSTALL_ENVOY_SNMP_V3_TARGET)

struct SNMP_TARGET_ADDR_S;
extern sbits32_t  SNMP_NV_V3_TAddr_Add_Mod     (struct SNMP_TARGET_ADDR_S *,
                                                struct SNMP_TARGET_ADDR_S *,
                                                sbits32_t);
extern sbits32_t  SNMP_v3_taddr_test     (struct SNMP_PKT_S *, struct VB_S *,
                                          struct SNMP_TARGET_ADDR_S *,
                                          struct SNMP_TARGET_ADDR_S *);
extern void       SNMP_v3_taddr_set      (struct SNMP_PKT_S *, struct VB_S *,
                                         struct SNMP_TARGET_ADDR_S *,
                                         struct SNMP_TARGET_ADDR_S *);
extern void       SNMP_v3_taddr_backout  (struct SNMP_TARGET_ADDR_S *,
                                         struct SNMP_TARGET_ADDR_S *);
extern int        SNMP_v3_taddr_undo     (struct SNMP_PKT_S *, struct VB_S *,
                                         struct SNMP_TARGET_ADDR_S *,
                                         struct SNMP_TARGET_ADDR_S *);
extern void       SNMP_v3_taddr_finished (void);

struct SNMP_TARGET_PARAMS_S;
extern sbits32_t  SNMP_NV_V3_TParam_Add_Mod     (struct SNMP_TARGET_PARAMS_S *,
                                                 struct SNMP_TARGET_PARAMS_S *,
                                                 sbits32_t);
extern sbits32_t  SNMP_v3_tparam_test    (struct SNMP_PKT_S *, struct VB_S *,
                                          struct SNMP_TARGET_PARAMS_S *,
                                          struct SNMP_TARGET_PARAMS_S *);
extern void       SNMP_v3_tparam_set    (struct SNMP_PKT_S *, struct VB_S *,
                                         struct SNMP_TARGET_PARAMS_S *,
                                         struct SNMP_TARGET_PARAMS_S *);
extern void       SNMP_v3_tparam_backout  (struct SNMP_TARGET_PARAMS_S *,
                                           struct SNMP_TARGET_PARAMS_S *);
extern int        SNMP_v3_tparam_undo     (struct SNMP_PKT_S *, struct VB_S *,
                                           struct SNMP_TARGET_PARAMS_S *,
                                           struct SNMP_TARGET_PARAMS_S *);
extern void       SNMP_v3_tparam_finished (void);

#if (INSTALL_ENVOY_SNMP_V3_NOTIFY)

struct SNMP_NOTIFY_S;
extern sbits32_t  SNMP_NV_V3_Notify_Add_Mod     (struct SNMP_NOTIFY_S *,
                                                 struct SNMP_NOTIFY_S *,
                                                 sbits32_t);
extern sbits32_t  SNMP_v3_notify_test    (struct SNMP_PKT_S *, struct VB_S *,
                                          struct SNMP_NOTIFY_S *,
                                          struct SNMP_NOTIFY_S *);
extern void       SNMP_v3_notify_set    (struct SNMP_PKT_S *, struct VB_S *,
                                         struct SNMP_NOTIFY_S *,
                                         struct SNMP_NOTIFY_S *);
extern void       SNMP_v3_notify_backout  (struct SNMP_NOTIFY_S *,
                                           struct SNMP_NOTIFY_S *);
extern int        SNMP_v3_notify_undo     (struct SNMP_PKT_S *, struct VB_S *,
                                           struct SNMP_NOTIFY_S *,
                                           struct SNMP_NOTIFY_S *);
extern void       SNMP_v3_notify_finished (void);

struct SNMP_NOTIFY_FILTER_PROFILE_S;
extern sbits32_t  SNMP_NV_V3_NProf_Add_Mod     (struct SNMP_NOTIFY_FILTER_PROFILE_S *,
                                                struct SNMP_NOTIFY_FILTER_PROFILE_S *,
                                                sbits32_t);
extern sbits32_t  SNMP_v3_nprof_test    (struct SNMP_PKT_S *, struct VB_S *,
                                         struct SNMP_NOTIFY_FILTER_PROFILE_S *,
                                         struct SNMP_NOTIFY_FILTER_PROFILE_S *);
extern void       SNMP_v3_nprof_set    (struct SNMP_PKT_S *, struct VB_S *,
                                        struct SNMP_NOTIFY_FILTER_PROFILE_S *,
                                        struct SNMP_NOTIFY_FILTER_PROFILE_S *);
extern void       SNMP_v3_nprof_backout  (struct SNMP_NOTIFY_FILTER_PROFILE_S *,
                                          struct SNMP_NOTIFY_FILTER_PROFILE_S *);
extern int        SNMP_v3_nprof_undo     (struct SNMP_PKT_S *, struct VB_S *,
                                          struct SNMP_NOTIFY_FILTER_PROFILE_S *,
                                          struct SNMP_NOTIFY_FILTER_PROFILE_S *);
extern void       SNMP_v3_nprof_finished (void);

struct SNMP_NOTIFY_FILTER_S;
extern sbits32_t  SNMP_NV_V3_NFilt_Add_Mod     (struct SNMP_NOTIFY_FILTER_S *,
                                                struct SNMP_NOTIFY_FILTER_S *,
                                                sbits32_t);
extern sbits32_t  SNMP_v3_nfilt_test    (struct SNMP_PKT_S *, struct VB_S *,
                                         struct SNMP_NOTIFY_FILTER_S *,
                                         struct SNMP_NOTIFY_FILTER_S *);
extern void       SNMP_v3_nfilt_set    (struct SNMP_PKT_S *, struct VB_S *,
                                        struct SNMP_NOTIFY_FILTER_S *,
                                        struct SNMP_NOTIFY_FILTER_S *);
extern void       SNMP_v3_nfilt_backout  (struct SNMP_NOTIFY_FILTER_S *,
                                          struct SNMP_NOTIFY_FILTER_S *);
extern int        SNMP_v3_nfilt_undo     (struct SNMP_PKT_S *, struct VB_S *,
                                          struct SNMP_NOTIFY_FILTER_S *,
                                          struct SNMP_NOTIFY_FILTER_S *);
extern void       SNMP_v3_nfilt_finished (void);

#endif /* #if (INSTALL_ENVOY_SNMP_V3_NOTIFY) */
#endif /* #if (INSTALL_ENVOY_SNMP_V3_TARGET) */
#endif /* #if (INSTALL_ENVOY_SNMP_VERSION_3) */

#define MAX_NVF 128
extern char NV_Config_Static[];
extern char NV_Old_Config_Static[];
extern char NV_Temp_Config_Static[];

extern char *NV_Config_File;
extern char *NV_Old_Config_File;
extern char *NV_Temp_Config_File;

extern int NV_Read_Only;
extern int NV_Views_From_Config;

#endif
